package routers

import (
	v1 "gomicro-sharemod/gateway-api/controllers/v1"
	v2 "gomicro-sharemod/gateway-api/controllers/v2"
	"gomicro-sharemod/gateway-api/middlewares"
	"gomicro-sharemod/gateway-api/tools"

	// swaggerfiles "github.com/swaggo/files"
	// ginSwagger "github.com/swaggo/gin-swagger"

	"github.com/gin-gonic/gin"
)

func ApiRouters(r *gin.Engine) {

	// ------------------ 前端 v1 版之非权限路由开始 ------------------
	v1FrontendUnauthGroupRouter := r.Group("/api/frontend/v1")
	{
		// --------------------- 杂项路由开始 --------------------
		//
		// r.GET("/captcha", func(ctx *gin.Context) {
		// 	tools.GenerateCaptcha(ctx, 4)
		// })

		// base64Captcha
		v1FrontendUnauthGroupRouter.GET("/captcha", func(ctx *gin.Context) {
			id, b64s, err := tools.MakeCaptcha()
			if err != nil {
				ctx.JSON(200, gin.H{
					"code": 400,
					"data": nil,
					"msg":  err.Error(),
				})
				return
			}

			ctx.JSON(200, gin.H{
				"code": 200,
				"data": map[string]interface{}{
					"captchaId":    id,
					"captchaImage": b64s,
				},
				"msg": "",
			})
		})

		// 生成二维码
		v1FrontendUnauthGroupRouter.GET("/qrcode", func(ctx *gin.Context) {
			// qrcode, err := tools.GenerateQrcode(ctx, "https://www.itrident.com.cn", "string")
			qrcode, err := tools.GenerateQrcode(ctx, "https://www.itrident.com.cn", "image")
			if err != nil {
				ctx.String(400, err.Error())
				return
			}

			ctx.String(200, qrcode)
		})
		// --------------------- 杂项路由结束 --------------------

		// +++++++++++++++ Rabbit路由开始 +++++++++++++++
		// 普通队列
		v1FrontendUnauthGroupRouter.GET("rabbit/simpleProducer", v1.RabbitController{}.SimpleProducer)

		// 工作队列
		v1FrontendUnauthGroupRouter.GET("rabbit/workProducer", v1.RabbitController{}.WorkProducer)

		// 广播队列
		v1FrontendUnauthGroupRouter.GET("rabbit/fanoutProducer", v1.RabbitController{}.FanoutProducer)

		// 定向路由类型消息
		v1FrontendUnauthGroupRouter.GET("rabbit/directProducer", v1.RabbitController{}.DirectProducer)

		// 主题类型交换机
		v1FrontendUnauthGroupRouter.GET("rabbit/topicProducer", v1.RabbitController{}.TopicProducer)

		// 重试案例
		v1FrontendUnauthGroupRouter.GET("rabbit/retryProducer", v1.RabbitController{}.RetryProducer)

		// 惰性队列
		v1FrontendUnauthGroupRouter.GET("rabbit/lazyProducer", v1.RabbitController{}.LazyProducer)

		// 幂等性案列
		v1FrontendUnauthGroupRouter.GET("rabbit/idempotentProducer", v1.RabbitController{}.IdempotentProducer)

		// 死信队列
		v1FrontendUnauthGroupRouter.GET("rabbit/deadProducer", v1.RabbitController{}.DeadProducer)

		// 延迟消息
		v1FrontendUnauthGroupRouter.GET("rabbit/delayProducer", v1.RabbitController{}.DelayProducer)

		// 消息过期
		v1FrontendUnauthGroupRouter.GET("rabbit/messageExpiredProducer", v1.RabbitController{}.MessageExpiredProducer)

		// 队列过期
		v1FrontendUnauthGroupRouter.GET("rabbit/queueExpiredProducer", v1.RabbitController{}.QueueExpiredProducer)

		// 备用交换机
		v1FrontendUnauthGroupRouter.GET("rabbit/backExchangeProducer", v1.RabbitController{}.BackExchangeProducer)

		// 应答模式生产者
		v1FrontendUnauthGroupRouter.GET("rabbit/ackModeProducer", v1.RabbitController{}.AckModeProducer)

		// 生产者Return模式,消息发送至队列时,队列返回
		v1FrontendUnauthGroupRouter.GET("rabbit/returnProducer", v1.RabbitController{}.ReturnProducer)

		// 消息丢失处理机制: 生产者Confirm模式,消息发送至交换机时,交换机返回确认
		v1FrontendUnauthGroupRouter.GET("rabbit/confirmProducer", v1.RabbitController{}.ConfirmProducer)

		// 优先级队列
		v1FrontendUnauthGroupRouter.GET("rabbit/priorityProducer", v1.RabbitController{}.PriorityProducer)

		// 三叉戟队列
		v1FrontendUnauthGroupRouter.GET("rabbit/tridentProducer", v1.RabbitController{}.TridentProducer)
		// +++++++++++++++ Rabbit路由结束 +++++++++++++++

		// ++++++++++++++++ 用户路由开始 ++++++++++++++++
		// 登录
		v1FrontendUnauthGroupRouter.POST("user/login", v1.UserController{}.Login)

		// 手机号登录
		v1FrontendUnauthGroupRouter.POST("user/mobileLogin", v1.UserController{}.MobileLogin)

		// 使用微信手机号登录
		v1FrontendUnauthGroupRouter.POST("user/wxMobileLogin", v1.UserController{}.WxMobileLogin)

		// 登录发送验证码
		v1FrontendUnauthGroupRouter.POST("user/loginSendCode", v1.UserController{}.LoginSendCode)

		// 邮箱忘记密码发送验证码
		v1FrontendUnauthGroupRouter.POST("user/emailForgotPasswordSendCode", v1.UserController{}.EmailForgotPasswordSendCode)

		// 邮箱忘记密码
		v1FrontendUnauthGroupRouter.POST("user/emailForgotPassword", v1.UserController{}.EmailForgotPassword)

		// 手机忘记密码发送验证码
		v1FrontendUnauthGroupRouter.POST("user/mobileForgotPasswordSendCode", v1.UserController{}.MobileForgotPasswordSendCode)

		// 手机忘记密码
		v1FrontendUnauthGroupRouter.POST("user/mobileForgotPassword", v1.UserController{}.MobileForgotPassword)

		// QQ登录
		v1FrontendUnauthGroupRouter.POST("user/qqLogin", v1.UserController{}.QqLogin)

		// 用户注册
		v1FrontendUnauthGroupRouter.POST("user/register", v1.UserController{}.Register)
		// ++++++++++++++++ 用户路由结束 ++++++++++++++++

		// ++++++++++++++++ 首页路由开始 ++++++++++++++++
		//首页
		v1FrontendUnauthGroupRouter.GET("/", v1.IndexController{}.Index)

		// 测试
		v1FrontendUnauthGroupRouter.GET("index/demo", v1.IndexController{}.Demo)

		// 测试发邮件
		v1FrontendUnauthGroupRouter.GET("index/demoSendEmail", v1.IndexController{}.DemoSendEmail)

		// 测试发短信
		v1FrontendUnauthGroupRouter.GET("/index/demoSendSms", v1.IndexController{}.DemoSendSms)

		// 测试请求参数
		v1FrontendUnauthGroupRouter.POST("/index/testRequestParams", v1.IndexController{}.TestRequestParams)

		// http请求测试
		v1FrontendUnauthGroupRouter.GET("/index/httpRequestDemo", v1.IndexController{}.HttpRequestDemo)

		// redis 分布式锁测试
		v1FrontendUnauthGroupRouter.GET("/index/redisLockDemo", v1.IndexController{}.RedisLockDemo)

		// redis 分片集群测试
		v1FrontendUnauthGroupRouter.GET("/index/redisClusterDemo", v1.IndexController{}.RedisClusterDemo)

		// redis 哨兵集群测试1
		v1FrontendUnauthGroupRouter.GET("/index/redisSentinelDemo1", v1.IndexController{}.RedisSentinelDemo1)

		// redis 哨兵集群测试
		v1FrontendUnauthGroupRouter.GET("/index/redisSentinelDemo", v1.IndexController{}.RedisSentinelDemo)

		// ++++++++++++++++ 首页路由结束 ++++++++++++++++

		// ++++++++++++++++ 地区路由开始 ++++++++++++++++
		v1FrontendUnauthGroupRouter.GET("region/getRegions", v1.RegionController{}.GetRegions)
		// ++++++++++++++++ 地区路由结束 ++++++++++++++++
	}
	// ------------------ 前端 v1 版之非权限路由结束 ------------------

	// ------------------- 前端 v1 版之权限路由开始 -------------------
	v1FrontendAuthGroupRouter := r.Group("/api/frontend/v1")
	v1FrontendAuthGroupRouter.Use(middlewares.UserAuthMiddleware)
	{

		// ++++++++++++++++ 用户路由开始 ++++++++++++++++
		// 刷新token
		v1FrontendAuthGroupRouter.POST("user/refreshToken", v1.UserController{}.RefreshToken)

		// 编辑用户
		v1FrontendAuthGroupRouter.POST("user/edit", v1.UserController{}.Edit)

		// 修改手机号
		v1FrontendAuthGroupRouter.POST("user/editMobile", v1.UserController{}.EditMobile)

		// 修改邮箱
		v1FrontendAuthGroupRouter.POST("user/editEmail", v1.UserController{}.EditEmail)

		// 修改密码
		v1FrontendAuthGroupRouter.POST("user/changePassword", v1.UserController{}.ChangePassword)

		// 编辑用户状态
		v1FrontendAuthGroupRouter.GET("user/editStatus", v1.UserController{}.EditStatus)

		// 用户列表
		v1FrontendAuthGroupRouter.GET("user/list", v1.UserController{}.List)

		// 获取用户详情
		v1FrontendAuthGroupRouter.GET("user/detail", v1.UserController{}.Detail)

		// 猜你喜欢的商品
		v1FrontendAuthGroupRouter.GET("user/guessLikeGoods", v1.UserController{}.GuessLikeGoods)
		// ++++++++++++++++ 用户路由结束 ++++++++++++++++
	}
	// ------------------- 前端 v1 版之权限路由结束 -------------------

	// ==============================================================
	// **************************************************************
	// **************************************************************
	// ==============================================================

	// ------------------ 前端 v2 版之非权限路由开始 ------------------
	v2FrontendUnauthGroupRouter := r.Group("/api/frontend/v2")
	{
		v2FrontendUnauthGroupRouter.GET("/", v2.IndexController{}.Index)
	}
	// ------------------ 前端 v2 版之非权限路由结束 ------------------

	// ------------------- 前端 v2 版之权限路由开始 -------------------
	// v2FrontendAuthGroupRouter := r.Group("/api/frontend/v2")
	// v2FrontendAuthGroupRouter.Use(middlewares.UserAuthMiddleware)
	// {

	// }
	// ------------------- 前端 v2 版之权限路由结束 -------------------

	// ==============================================================
	// **************************************************************
	// **************************************************************
	// ==============================================================

	// ------------------ 管理 v1 版之非权限路由开始 ------------------
	v1MgrUnauthGroupRouter := r.Group("/api/mgr/v1")
	{
		v1MgrUnauthGroupRouter.GET("/", v1.IndexController{}.Backend)

		// --------------------- 账户路由开始 ---------------------
		v1MgrUnauthGroupRouter.POST("/account/login", v1.AccountController{}.Login)
		// --------------------- 账户路由结束 ---------------------
	}
	// ------------------ 管理 v1 版之非权限路由结束 ------------------

	// ------------------- 管理 v1 版之权限路由开始 -------------------
	v1MgrAuthGroupRouter := r.Group("/api/mgr/v1")
	v1MgrAuthGroupRouter.Use(middlewares.AuthMiddleware)
	{
		// --------------------- 账户路由开始 ---------------------
		// 详情
		v1MgrAuthGroupRouter.GET("/account/detail", v1.AccountController{}.Detail)

		// 获取当前登录账户详情
		v1MgrAuthGroupRouter.GET("/account/getCurrentLoginAccountDetail", v1.AccountController{}.GetCurrentLoginAccountDetail)
		// --------------------- 账户路由结束 ---------------------
	}
	// ------------------- 管理 v1 版之权限路由结束 -------------------

	// ------------------ 管理 v2 版之非权限路由开始 ------------------
	v2MgrUnauthGroupRouter := r.Group("/api/mgr/v2")
	{
		v2MgrUnauthGroupRouter.GET("/", v2.IndexController{}.Backend)
	}
	// ------------------ 管理 v2 版之非权限路由结束 ------------------

	// ------------------- 管理 v2 版之权限路由开始 -------------------
	// v2MgAuthGroupRouter := r.Group("/api/mgr/v2")
	// v2MgAuthGroupRouter.Use(middlewares.AuthMiddleware)
	// {
	// 	v2MgAuthGroupRouter.GET("/", v2.IndexController{}.Backend)
	// }
	// ------------------- 管理 v2 版之权限路由结束 -------------------

}
